package logic

import (
	"context"
	"qimao-fiction/models/mysql"

	"qimao-fiction/qimaorpc/internal/svc"
	"qimao-fiction/qimaorpc/qimaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookUpdateLogic {
	return &BookUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookUpdateLogic) BookUpdate(in *qimaorpc.BookUpdateRequest) (*qimaorpc.BookUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var book mysql.Book
	mysql.DB.Debug().Where("id = ?", in.UserId).Find(&book)
	book.Title = in.Title
	book.Brief = in.Brief
	book.Img = in.Img
	mysql.DB.Debug().Updates(&book)
	return &qimaorpc.BookUpdateResponse{
		Id: int64(book.ID),
	}, nil
}
